package com.zhiyou100.crowd.controller;


import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhiyou100.IService.ILetterService;
import com.zhiyou100.pojo.ViewLet;


@Controller
@RequestMapping("letter")
public class LetterController {

	//导入service
	@Resource(name="letterService")
	private  ILetterService letterService;
	
	// 跳转页面
	@RequestMapping("use_letter.do")
	public String page() {
		return "forward:queryLet.do";
	}
	
	//评论查询
	@RequestMapping("queryLet.do")
	public String query(@RequestParam(required=true,defaultValue="1")Integer page ,HttpServletRequest request) {
		//调用查询方法
		PageHelper.startPage(page,5);
		List<ViewLet> viewLets = letterService.queryAll();
	
		//将数据载入域中
		PageInfo<ViewLet> pageInfo = new PageInfo<ViewLet>(viewLets);
		request.setAttribute("page", pageInfo);
		request.setAttribute("user_let", viewLets);
		return "use_letter";
	}
	
	//删除
	@RequestMapping("deleteLet.do") 
		public String deleteLetter(Integer le_id) {
			System.out.println(le_id);
			Integer letter = letterService.deleteLetter(le_id);
			if(letter==2) {
				return "forward:queryLet.do";
				}else {
			return "forward:queryLet.do";
		}
	}
}
